package com.wlh.animation.demo;/*
 * Copyright (C) 2016 Facishare Technology Co., Ltd. All Rights Reserved.
 */

import java.util.ArrayList;
import java.util.List;

import com.wlh.animation.R;
import com.wlh.animation.ScrollListView;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ArrayAdapter;

/**
 * Created by weilh on 2016/1/26.
 */
public class SlideAnimAct1 extends AppCompatActivity {
    private ScrollListView list;
    private View root_view;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_slide_anim1);
        setTitle("滑动特效");
        list = (ScrollListView) findViewById(R.id.list);
        root_view = findViewById(R.id.root_view);
        List<String> itemList = new ArrayList<>();
        for (int i = 0; i < 50; i++) {
            itemList.add("" + i);
        }
        list.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, itemList ));
        list.setListener(new ScrollListView.ListScrollListener() {
            @Override
            public void scroll(float y) {
                float scrollResult = root_view.getScrollY()-y;
                if (scrollResult > 200) {
                    scrollResult = 200f;
                } else if (scrollResult < 0) {
                    scrollResult = 0f;
                }
                root_view.scrollTo(0, (int) scrollResult);
            }

            @Override
            public void scrollEnd() {
                if (root_view.getScrollY() > 100) {
                    root_view.scrollTo(0, 200);
                } else {
                    root_view.scrollTo(0,0);
                }
            }
        });

    }
}